<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //内部函数访问外部函数的变量，全局无法直接修改，实现数据的私有化，但容易引起内存泄漏
    function count() {
      let i = 0
      function fn() {
        i++
        console.log(i)
      }
      return fn
    }
    let f = count()
    f()
  </script>
</body>

</html>